﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

public partial class usercontrol_ucOrder : System.Web.UI.UserControl
{
    TblOrderDAO orderDAO = new TblOrderDAO(Global.CONNECTION_STRING);
    DateTime _dt;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // hien thi ngay dau tien va cuoi cung cua thang
            _dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DateTime date = _dt;
            txtFrDate.Text = _dt.ToString("dd/MM/yyy");
            // txtToDate.Text = DateTime.Now.ToString("dd/MM/yyyy");           
            int ngay = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
            int thang = DateTime.Now.Month;
            int nam = DateTime.Now.Year;
            txtToDate.Text = Convert.ToDateTime(nam + "/" + thang + "/" + ngay).ToString("dd/MM/yyyy");
            LoadOrderList();
        }
        if (Request.Params["__EVENTTARGET"] != null)
        {
            if (Request.Params["__EVENTTARGET"].IndexOf("DataPagerImages") > 0)
            {
                LoadOrderList();
            }
        }
    }

    private void LoadOrderList()
    {
        try
        {
            DataTable dt = orderDAO.GetOrderLst(Global.ConvertToDate(txtFrDate.Text), Global.ConvertToDate(txtToDate.Text), ((TblUserAccount)Session[Global.SESSION_LOGGED_USER]).Email);
            lvItem.DataSource = dt;
            lvItem.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        LoadOrderList();
    }

    protected void lvItem_SelectedIndexChanged(object sender, EventArgs e)
    {
        lvItem.DataBind();
    }
    protected void DataPagerImages_PreRender(object sender, EventArgs e)
    {
        lvItem.DataBind();
    }
}
